package com.monkey.core.config;

import com.monkey.model.monkey.MonkeyTradeData;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * desc:
 * auth: chenxiaobin
 * data: 2018/1/21.
 */
@Configuration
public class MyAppConfig {

    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
        return new JedisConnectionFactory();
    }

    @Bean
    RedisTemplate<String, MonkeyTradeData> redisTemplate() {
        final RedisTemplate<String, MonkeyTradeData> template = new RedisTemplate<>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new Jackson2JsonRedisSerializer<>(MonkeyTradeData.class));
        return template;
    }
}
